package com.hr.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.hr.entity.ConfigFileSecondKind;
import com.hr.mapper.ConfigFileSecondKindMapper;
import com.hr.service.ConfigFileSecondKindService;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ConfigFileSecondKindServiceImpl implements ConfigFileSecondKindService {
    @Autowired
    private ConfigFileSecondKindMapper configFileSecondKindMapper;

    /**
     * 查询二级机构
     * @return
     */
    @Override
    public List<ConfigFileSecondKind> queryList(ConfigFileSecondKind configFileSecondKind) {
        QueryWrapper<ConfigFileSecondKind> queryWrapper = new QueryWrapper<ConfigFileSecondKind>();
        if(configFileSecondKind.getFirstKindId() !=null && !configFileSecondKind.getFirstKindId().isEmpty()){
            queryWrapper.eq("first_kind_id",configFileSecondKind.getFirstKindId());
        }
        List<ConfigFileSecondKind> secondList = configFileSecondKindMapper.selectList(queryWrapper);
        return secondList;
    }

    /**
     * 保存/修改
     * @param configFileSecondKind
     * @return
     */
    @Override
    public boolean save(ConfigFileSecondKind configFileSecondKind) {
        int row=0;
        if(configFileSecondKind.getFskid()==null){
            row=configFileSecondKindMapper.insert(configFileSecondKind);
        }else{
            row=configFileSecondKindMapper.updateById(configFileSecondKind);
        }

        return row>0;
    }

    /**
     * 删除
     * @param fskid
     * @return
     */
    @Override
    public boolean del(Integer fskid) {
        int i = configFileSecondKindMapper.deleteById(fskid);
        return i>0;
    }

    /**
     * 单值查询
     * @param fskid
     * @return
     */
    @Override
    public ConfigFileSecondKind queryById(Integer fskid) {
        ConfigFileSecondKind configFileSecondKind = configFileSecondKindMapper.selectById(fskid);
        return configFileSecondKind;
    }

//    /**
//     * 二级机构设置 的业务
//     */
//    @Override
//    public List<ConfigFileSecondKind> queryList() {
//        //构建一个无参的对象
//        QueryWrapper<ConfigFileSecondKind> queryWrapper = new QueryWrapper();
//        //查询一个没有条件的sql语句（mybatis-puls生成的）
//        List list = configFileSecondKindMapper.selectList(queryWrapper);
//        //返回结果集
//        return list;
//    }
}
